/**
 * @description 朋友圈 业务逻辑
 * @author malin
 */

const { SuccessModel, ErrorModel } = require('../model/ResModel')
const { create, getPyqListByUser } = require('../services/pyq')
const { createPyqFailed, getPyqListByUserFailed } = require('../model/ErrorInfo')

/**
 * 发布朋友圈
 * @param {number} userId 
 * @param {string} content 
 * @param {string} image 
 */
async function createPyq({ userId, content, image}) {
    // 调用service
    let result = await create(userId, content, image)
    if (result) {
        return new SuccessModel()
    }
    return new ErrorModel(createPyqFailed)
}

/**
 * 查询用户的朋友圈列表
 * @param {string} userName 
 * @param {number} page 
 */
async function getPyqList(userName, page) {
    const result = await getPyqListByUser(userName, page)
    if (result) {
        return new SuccessModel(result)
    }
    return new ErrorModel(getPyqListByUserFailed)
}

module.exports = {
    createPyq,
    getPyqList
}
 